﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Easy.Authorization.Models;
using Easy.Authorization.Repository;
using Easy.Authorization.Repository.Query;
using Easy.Common.RegisterType;


namespace Easy.Authorization.Business
{
    [RegisterType(typeof(Aut_UsersBusiness))]
    class Aut_UsersBusiness
    {
        IAut_UsersQueryRepository _aut_UsersQueryRepository;
        IAut_UsersRepository _aut_UsersRepository;

        public Aut_UsersBusiness(IAut_UsersQueryRepository aut_UsersQueryRepository, IAut_UsersRepository aut_UsersRepository)
        {
            _aut_UsersQueryRepository = aut_UsersQueryRepository;
            _aut_UsersRepository = aut_UsersRepository;
        }


        public void CreateNew(Aut_Users aut_User)
        {
            _aut_UsersRepository.Add(aut_User);

            _aut_UsersRepository.UnitOfWork.Commit();
        }

        public void Update(Aut_Users aut_User)
        {
            _aut_UsersRepository.Update(aut_User);

            _aut_UsersRepository.UnitOfWork.Commit();
        }

        public void Delete(Aut_Users aut_User)
        {
            _aut_UsersRepository.Delete(aut_User);

            _aut_UsersRepository.UnitOfWork.Commit();
        }

        public Aut_Users FindById(Guid id)
        {
            return _aut_UsersRepository.FindById(id);
        }

        public Aut_Users FindByUserame(string username)
        {
            return _aut_UsersRepository.FindByUserame(username);
        }

        public IQueryable<Aut_Users> GetPaged(int pageIndex = 0, int pageCount = 25, string where = "", string orderBy = "")
        {
            return _aut_UsersQueryRepository.GetPaged(pageIndex, pageCount, where, orderBy);
        }
    }
}
